from copy import deepcopy
from random import randint
import time

#  本金
money = 6000
MONEE = money

# 购物车
mycart = []  #  append
# 商品
CT = [
    ["1",200],
    ["2",700],
    ["3",2900],
    ["4",4750],
    ["5-08",1700],
    ["6",500],
]
T = [
    ["1",200],
    ["2",700],
    ["3",2700],
    ["4",4750],
    ["5-08",1700],
    ["6",400],
]
coup = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.5]
usercoup = input("请输入0~100之间你的幸运数字来抽取全场优惠券！")
if usercoup.isdigit():
    usercoup = float(usercoup)
    if (usercoup - randint(0,100)) < 10:
        yh = coup[randint(0,4)]
        print("恭喜您抽中",(yh*10),"折优惠！来买武器吧~")
    elif (usercoup - randint(0,100)) < 25:
        yh = coup[randint(5, 8)]
        print("恭喜您抽中", (yh*10), "折优惠！来买武器吧~")
    else:
        yh = usercoup[9]
        print("哎呀！您可真是太幸运啦！！抽到本次神秘大奖！！当当当~~",(yh*10),"折特大优惠！！，去买最贵的！hhhh")
else:
    yh = 1
    print("输入非法，默认您已选择放弃此次优惠活动，后续活动敬请期待！")
print("-----------欢迎来到CSGO------------")
cs = input("请选择阵营，CT or T,默认为T")
if cs == "CT":
    while True:
            for index,i in enumerate(CT):
                print(index + 1,i)
            print("------------------------------------")
            num  = input("请输入你要购买的商品编号：")
            if num == "q" or  num == "Q":
                print("欢迎下次光临！谢谢！")
                break
            elif  num.isdigit(): # "5"  --> 5  true
                num = int(num)
                if num <= 0  or  num > len(CT):
                    print("没有这个商品！稍后重试！")
                else:
                    if money >=  CT[num-1][1]:
                        if yh != 1:
                            mycart.append(deepcopy(CT[num - 1]))
                            money -= CT[num - 1][1]*yh/10
                            yh = 1
                            print("恭喜，购买成功！已使用优惠券，您的余额还剩", money, "元！")
                        else:
                            mycart.append(deepcopy(CT[num-1]))
                            money -=  CT[num-1][1]
                            print("恭喜，购买成功！您的余额还剩",money,"元！")
                    else:
                        print("对不起，钱不够！穷鬼！")
            else:
                print("非法输入！")
else:
    while True:
        for index, i in enumerate(T):
            print(index + 1, i)
        print("------------------------------------")
        num = input("请输入你要购买的商品编号：（输入th可进行退货）")
        if num == "q" or num == "Q":
            print("欢迎下次光临！谢谢！")
            break
        elif num.isdigit():  # "5"  --> 5  true
            num = int(num)
            if num <= 0 or num > len(T):
                print("没有这个商品！稍后重试！")
            else:
                if money >= T[num - 1][1]:
                    if yh != 1:
                        mycart.append(deepcopy(T[num - 1]))
                        money -= T[num - 1][1] * yh / 10
                        yh = 1
                        print("恭喜，购买成功！已使用优惠券，您的余额还剩", money, "元！")
                    else:
                        mycart.append(deepcopy(T[num - 1]))
                        money -= T[num - 1][1]
                        print("恭喜，购买成功！您的余额还剩", money, "元！")
                else:
                    print("对不起，钱不够！穷鬼！")
        elif num == "th":
            th = input("请选择要退货的商品序号")
            if th.isdigit():
                th = int(th)
                thh = 1
                for i in range(0,len(mycart)):
                    if mycart[i][0] == T[th-1][0]:
                        mycart.pop(i)
                        money += T[th-1][1]
                        thh -= 1
                        print("退货成功！")
                        break
                    else:
                        continue
                if thh == 1:
                    th1 = 1
                    for i in range(0, len(mycart)):
                        if mycart[i][0] == T[th - 1][0]:
                            mycart.pop(i)
                            money += T[th - 1][1]
                            thh -= 1
                            print("退货成功！")
                            break
                        else:
                            continue
                else:
                    continue
                if thh == 1 and th1 == 1:
                    print("购物车没有该物品，你自己造的吗？？")
                else:
                    continue
            else:
                print("非法输入，返回上一级。")
        else:
            print("非法输入！")
# 打印购物小条
print("----拿好购物小条-----")
for i in range(0,len(mycart)):
    mycart[i].append(1)
for i in range(0,len(mycart)):
    count = 1
    if i <= len(mycart)-1 and mycart[i][2] == 1:
        for j  in range(i,len(mycart)):
            if j < (len(mycart)-1) and mycart[i] == mycart[j+1]:
                count += 1
                mycart[j+1].pop()
                mycart[j+1].append(0)
            else:
                continue
        print(i + 1, mycart[i][0],mycart[i][1], "x", count)
    else:
        continue
print("-----------------------")
current_timestamp = time.time()
local_time = time.localtime(current_timestamp)
print(f"购买时间：{time.strftime('%Y-%m-%d %H:%M:%S', local_time)}")
print("您共消费",(MONEE-money),"元，卡余额还剩￥",money,"元！")




